var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();
let interstitialAd = null;

Page({
    data: {
        motto: "Hello World",
        userInfo: {},
        hasUserInfo: !1,
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        showBack: 0,
        height: 2 * app.globalData.height + 20,
        loading: !1,
        shareshow: !1,
        nav: {
            title: "参与记录",
            showHome: !0,
            isHomePage: !1
        },
        characters: [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ],
        showcopy: !0,
        share: {
            images: "",
            member_id: "",
            text: ""
        },
        selectIndex: 0,
        p: 1,
        isover: !1,
        apply: [],
        use_substance: 1
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        }), that.luckLog();
    },
    onLoad: function(t) {
        that = this, t.parent_id && wx.setStorageSync("parent_id", t.parent_id);
    },
    btnClick: function(t) {
        var a = t.currentTarget.id;
        a != this.data.selectIndex && (this.setData({
            apply: [],
            p: 1,
            isover: !1,
            selectIndex: a
        }), 1 == a ? this.voteLog() : this.luckLog());
    },
    onShow: function() {
        if (wx.createInterstitialAd) {
            interstitialAd = wx.createInterstitialAd({
              adUnitId: 'adunit-42e141bfcfdcc315'
            })
            interstitialAd.onLoad(() => {})
            interstitialAd.onError((err) => {})
            interstitialAd.onClose(() => {})
          };
          
          // 在适合的场景显示插屏广告
          if (interstitialAd) {
            interstitialAd.show().catch((err) => {
              console.error(err)
            })
          };
    },
    luckLog: function() {
        var t = {
            action: "apply",
            contr: "luck",
            token: wx.getStorageSync("token"),
            p: this.data.p
        };
        _tools2.default.request(t, function(t) {
            var a = t.info.apply;
            1 < that.data.p && (a = that.data.apply.concat(a)), t.info.apply.length < 8 && that.setData({
                isover: !0
            }), that.setData({
                loading: !0,
                share: t.info.share,
                apply: a
            });
        });
    },
    voteLog: function() {
        var t = {
            action: "apply",
            contr: "cvote",
            token: wx.getStorageSync("token"),
            p: this.data.p
        };
        _tools2.default.request(t, function(t) {
            var a = t.info.apply;
            1 < that.data.p && (a = that.data.apply.concat(a)), t.info.apply.length < 8 && that.setData({
                isover: !0
            }), that.setData({
                loading: !0,
                share: t.info.share,
                apply: a
            });
        });
    },
    bindscrolltolower: function() {
        console.log(1111), this.data.isover || (this.data.p += 1, 0 == this.data.selectIndex ? this.luckLog() : this.voteLog());
    },
    gotoInfo: function(t) {
        var a = t.currentTarget.dataset.id;
        t.currentTarget.dataset.type;
        wx.navigateTo({
            url: "/bh_bargain/pages/userGame/userGame?id=" + a
        });
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.text,
            imageUrl: this.data.share.images,
            path: "bh_bargain/pages/index/index?parent_id=" + this.data.share.member_id
        };
    }
});